package com.si.anddos.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

import android.util.Log;

/**
 * 
 * @author Carlos Martinez
 * 
 * Trida by nemela byt zavisla na sitovem spojeni, mela by jen ukladat data nekam.
 * Bude zrejme treba udelat pro to nejaky interface nebo abstraktni tridu, aby bylo mozno vytvaret dalsi savery.
 * Nebylo by vubec spatne, kdyby byla potomkem nejakeho obecneho vystupniho streamu.
 */
public class FileSaver {

	private RandomAccessFile file;
	
	public FileSaver(File file) throws FileNotFoundException {
		
		this.file = new RandomAccessFile(file, "rw");
	}

	public void write(byte[] buffer, int bytes) throws IOException {
		
		this.file.write(buffer, 0, bytes);
	}
	
	public void close() throws IOException {
		
		this.file.close();
	}
	
	public long getPosition() throws IOException {
		
		return this.file.getFilePointer();
	}
	
	public void setPosition(long position) throws IOException {
		
		this.file.seek(position);
	}
	
	public long length() throws IOException {
	
		return this.file.length();
	}
}
